<template>
	<view class="audit-box">
		<TopBar :indexflag="true" :combakflag="true" :lang="false" :bottom="true" :title="$t('Login')"
			:barstyle="colortopic()">
		</TopBar>
		<view class="item-box">
			<view class="content">
				<u-icon :name="type=='employee'?'account-fill':'home-fill'" :color="colortopic()" size="68"></u-icon>
			</view>
			<view :class="i18nLocale=='ug'?'ug-from from-box':'from-box'">
				<view class="input-item">
					<u--input v-model="user.name" type="number" :placeholder="$t('NumberPlaceholder')" fontSize="28rpx"
						:adjustPosition='false'></u--input>
				</view>

				<view class="input-item">
					<u--input v-model="user.password" type="password" :placeholder="$t('Password')" fontSize="28rpx"
						:adjustPosition='false'></u--input>
				</view>
				<view class="login-button" @click="pwlogin">
					<text>{{$t('Login')}}</text>
				</view>
			</view>
		</view>
		<Loading :show="loadshow" bgColor="" iconName="circle" :text="$t('Loading')"></Loading>
		<Contact style="" :shopdata="mydata"></Contact>
		<u-toast ref="uToast" :message="notmessage"></u-toast>
	</view>
</template>

<script>
	import Contact from "@/components/Contact.vue"
	import {
		getshopone,
		getemployeeone,
		boosbind,
		employeebind
	} from '@/api/all.js';
	export default {
		components: {
			Contact
		},
		data() {
			return {
				type: '',
				loadshow: false,
				mydata: {
					mobile: '17690927591',
					wechat: '17690927591'
				},
				employee_id: '',
				shop_id: '',
				shopdata: '',
				employeedata: '',
				user: {
					name: '',
					password: ''
				},
				notmessage: '请仔细填写!',

			};
		},
		onLoad(e) {
			console.log(e, '+++')
			if (e.type) {
				this.type = e.type;
			}
		},
		computed: {
			i18nLocale() {
				return this.$i18n.locale;
			}
		},
		methods: {
			changeMobile(mobile) {
				uni.makePhoneCall({
					phoneNumber: mobile
				})

			},
			pwlogin() {
				let that = this;
				if (!that.user.name && !that.user.password) {
					that.$refs.uToast.show({
						top: 0,
						message: this.$t('PleaseFillCarefully'),
						color: '#fff',
						bgColor: '#f0ba53'
					})
					return;
				}
				if (that.type == 'shop') {
					that.loadshow = true;
					boosbind({
						mobile: that.user.name,
						password: that.user.password
					}).then((res) => {
						if (res.code == 200) {
							that.loadshow = false;
							that.$refs.uToast.show({
								top: 0,
								message: that.$t('AuthenticationSuccessful'),
								color: '#fff',
								bgColor: '#f0ba53'
							})
							//老板
							let data = res.body.shop;
							if (data) {
								this.$store.commit('setShopinfo', data);
								this.$store.commit('setShoptoken', data.token);
								if (this.$store.state.shoptoken) {
									setTimeout(() => {
										uni.redirectTo({
											url: '/pages/boos/main'
										});
									}, 200)
								}
							}

						} else {
							that.loadshow = false;
							that.$refs.uToast.show({
								top: 0,
								message: that.$t('AuthenticationFailed'),
								color: '#fff',
								bgColor: '#f0ba53'
							})
						}
					})
				}
				if (that.type == 'employee') {
					that.loadshow = true;
					employeebind({
						mobile: that.user.name,
						password: that.user.password
					}).then((res) => {
						if (res.code == 200) {
							that.loadshow = false;
							let data = res.body.data;
							that.$refs.uToast.show({
								top: 0,
								message: that.$t('AuthenticationSuccessful'),
								color: '#fff',
								bgColor: '#f0ba53'
							})
							this.$store.commit('setEmployeeinfo', data);
							this.$store.commit('setEmployeetoken', data.token);
							if (this.$store.state.employeetoken) {
								setTimeout(() => {
									uni.redirectTo({
										url: '/pages/employee/main'
									});
								}, 200)
							}
						} else if (res.code == 401) {
							that.loadshow = false;
							that.$refs.uToast.show({
								top: 0,
								message:that.$t('EgasiBilanBoglaning'),
								color: '#fff',
								bgColor: '#f0ba53'
							})
						} else {
							that.loadshow = false;
							that.$refs.uToast.show({
								top: 0,
								message: that.$t('AuthenticationFailed'),
								color: '#fff',
								bgColor: '#f0ba53'
							})
						}
					})
				}
			}

		}
	}
</script>

<style lang="scss" scoped>
	.audit-box {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		justify-content: space-around;

		.item-box {
			width: 100%;
			box-sizing: border-box;
			padding: 0rpx 20rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			.shop-box {
				width: 90%;
				display: flex;
				flex-direction: column;
				box-sizing: border-box;
				background-color: $uni-bg-color-box;
				border-radius: $uni-border-radius-base;
				box-shadow: $uni-bg-shadow;
				margin-top: 30rpx;
				padding: 50rpx 50rpx;

				view {
					padding: 5rpx 0rpx;
				}

				text {
					width: 50%;
				}
			}

			.from-box {
				width: 80%;
				border-radius: 30rpx;
				box-sizing: border-box;
				padding: 30rpx 30rpx;
				margin-top: 100rpx;
				display: flex;
				flex-direction: column;
				align-items: center;

				.input-item {
					width: 100%;
					margin: 10rpx 0rpx;
					display: flex;
					align-items: center;

					.title {
						width: 30%;
						display: flex;
						align-items: center;
						justify-content: center;
					}
				}

				.item {
					width: 100%;
					display: flex;
					align-items: center;
					margin-top: 50rpx;
					background-color: #fff;
					box-sizing: border-box;
					padding: 10rpx 20rpx;
					border-radius: 20rpx;

					.input {
						width: auto;
						padding: 10rpx 20rpx;
					}

					.title {
						width: 30%;
						// border-left: 2rpx solid $uni-border-color;

					}
				}

				.login-button {
					width: 70%;
					margin: 0 auto;
					padding: 20rpx 0rpx;
					background-color: $uni-color-topic;
					;
					display: flex;
					justify-content: center;
					align-items: center;
					margin-top: 100rpx;
					border-radius: $uni-border-radius-base;
					color: #fff;


					text {
						padding: 0rpx 20rpx;
					}
				}

			}



			// margin-top: 200rpx;
			.content {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.button {
					padding: 10rpx 50rpx;
					color: #fff;
					background-color: $uni-color-topic;
					margin-top: 30rpx;
					border-radius: $uni-border-radius-lg;
					font-size: $uni-font-size-lg;
				}

				text {
					padding: 20rpx 20rpx;
				}

				image {
					width: 300rpx;
				}
			}
		}
	}
</style>